#include<iostream>
using namespace std;
#define maxsize 10

typedef struct {//定义栈
	char data[maxsize];
	int top;
}sq;
void stackinit(sq& s){//初始化栈
	s.top = -1;
}
bool stackempty(sq s){//判断栈空
	if (s.top == -1) return true;
	else return false;
}
bool push(sq& s, char x){//放入元素
	if (s.top == maxsize - 1) return false;
	s.data[++s.top] = x;
	return true;
}
void pop(sq& s){//出栈
	if (s.top == -1) cout << "栈空" << endl;
	s.top--;
}
char gettop(sq s){//获取栈顶
	int x;
	if (s.top == -1) return -1;
	x = s.data[s.top];
	return x;
}
void destorystack(sq& s) {//释放栈
	if (s.top != -1) free(s.data);
	s.top = -1;
}

int main() {
	sq s;
	cout << "创建栈s" << endl;
	stackinit(s);//初始化栈
	if (stackempty(s)) { cout << "当前栈s为空" << endl; }
	else { cout << "当前栈s不为空" << endl; }
	push(s, 'a');
	push(s, 'b');
	push(s, 'c');
	push(s, 'd');
	push(s, 'e');
	cout << "输入元素a,b,c,d,e" << endl;
	if (stackempty(s)) { cout << "当前栈s为空" << endl; }
	else { cout << "当前栈s不为空" << endl; }
	cout << "当前的出栈序列为：";
	while (!stackempty(s))
	{
		cout << gettop(s) << " ";
		s.top--;
	}
	cout << endl;
	if (stackempty(s)) { cout << "当前栈s为空" << endl; }
	else { cout << "当前栈s不为空" << endl; }
	destorystack(s);//释放栈
	return 0;
}